package com.common.glide.module;

import android.content.Context;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.util.Log;

import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.Registry;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.load.engine.cache.DiskLruCacheFactory;
import com.bumptech.glide.module.AppGlideModule;
import com.common.glide.GlideUtil;

/**
 * @author mrwim
 * @version 1.0
 * @since 2018-09-17
 */
@GlideModule
public class BaseModule extends AppGlideModule {
    private String appRootPath="";
    private String sdRootPath= Environment.getExternalStorageDirectory().getPath();
    @Override
    public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
        super.applyOptions(context, builder);
        appRootPath=context.getCacheDir().getPath();
        builder.setDiskCache(
                new DiskLruCacheFactory(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) ?
                        sdRootPath : appRootPath+ GlideUtil.DISKCACHENAME, GlideUtil.MAXSIZE));
    }

    @Override
    public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
        super.registerComponents(context, glide, registry);
    }
}
